
#############################################################################################################################################################################################################################

GENERAL INFORMATION

1. Title of project: "Using sex and sex ratio specific Robertson covariances to investigate within-sex and across-sex selective effects on reproduction related traits in Drosophila melanogaster"

2. Author Information
	A. Corresponding Author Contact Information
		Name: Manas Geeta Arun
		Institution: Instutute of Ecology and Evolution, the University of Edinburgh
		Address: Ashworth Laboratories, Charlotte Auerbach Road, Edinburgh - EH9 3FL, United Kingdom.
		Email: manas.geetaarun@ed.ac.uk, manassamant2000@gmail.com

	B. Principal Investigator Contact Information
		Name: Prof. N. G. Prasad
		Institution: Indian Institute of Science Education and Research, Mohali
		Address: IISER Mohali, Sector 81, Knowledge City, SAS Nagar, Punjab - 140306, India.
		Email: prasad@iisermohali.ac.in


3. Duration of data collection: 2018-2020

4. Geographic location of data collection: Mohali, Punjab, India 

5. Information about funding sources that supported the collection of the data: IISER Mohali, Govt. of India.

6. Abstract of the project:

Predicting the response to selection on a trait measured in one sex requires an understanding of (1) direct and indirect selection acting on the trait in the sex it is measured in (“within-sex selection”), and (2) direct and indirect selection experienced by the underlying loci when expressed in the opposite sex (“across-sex selection”). Expected response to within- and across-sex selection can be expressed as sex-specific Robertson Covariances (RCs), i.e., additive genetic covariance between the trait and female relative fitness, and the additive genetic covariance between the trait and male relative fitness. Using hemiclonal analysis in Drosophila melanogaster, we applied this framework to investigate the expected response to within-sex and across-sex selection experienced by a suite of traits involved in Interlocus Sexual Conflict (IeSC) at male biased, equal, and female biased adult sex ratios. Our results suggest that IeSC and sexual selection became stronger with the degree of male bias in adult sex ratio. The expected response to across-sex selection was small, and typically concordant with respect to the response to within-sex selection, suggesting that Intralocus Sexual Conflict was undetectable. On the contrary, our results suggest that across-sex selection may impart females a nearly 100% boost to their rate of adaptation. 

############################################################################################################################################################################################################################

#########################################
# Details of software packages required #
#########################################

All analyses are performed on R version ‘4.4.2’ and using rmarkdown 2.29.

Following packages (versions) are required:

RhpcBLASctl (0.23-42)
MCMCglmm (2.36)
standardize (0.2.2)
lmerTest (3.1-3)
ggplot2 (3.5.1)
cowplot (1.1.3)
latex2exp (0.9.6)
MASS (7.3-61)

############################
# Overview of the workflow #
############################

All empirical data used in this study is within "Comprehensive_traits.csv" which is stored in the root directory of the repository. It contains data on a large number of reproduction related traits (including fitness) on a large number of male and female individuals from 39 hemigenome lines. 

All analysis scripts are stored in the root directory of the repository. The analyses generates files (.jpg figures or .csv data files) which are stored within the subdirectories "null_distributions" and "Output". The .Rmd scripts also generate html outputs which are stored in the root directory. The analysis scripts have file names with numerical subscripts. These indicate the order in which these scripts must be run. If two or more scripts have the same numerical subscript in their filenames, scripts must be run in alphabetical order of their filenames.

Details of each file are provided below. Here, we provide an overview of the analysis workflow.

## (A) Generating null distributions for additive genetic variances for fitness and various traits

Since our quantitative genetic analyses (see below) use a Bayesian MCMC based approach to generate posterior distributions for additive genetic variances, the 95% credible intervals are constrained to be positive. Therefore, to test for presence of significant additive genetic variance, we generate null distributions by randomising the hemigenome line identity of each point.

(i) Run "0_create_parameter_grid.R" to generate "000_parameter_grid.txt" which contains command line arguments for running "0_randomise_traits.R". 

(ii) Run "0_randomise_fitness" 1000 times to generate 1000 output files containing model outputs post randomisation of hemigenome lines. This script requires a command line argument (could be 1, 2, 3, etc.) that is simply the replicate ID that gets attached to the output filename. These output files will be stored in the directory "null_distributions". We combine these 1000 files into a single file (retaining the header only from one of the files) to generate "fitness_randomised_NULL.csv". We performed this step on a computing cluster using "00000_control_randomise_fitness.sh".

(iii) Make sure std is set to TRUE in "0_randomise_traits.R". Run "0_randomise_traits.R" 16000 times, each time using command line arguments stored within "000_parameter_grid.txt". Each row of "000_parameter_grid.txt" supplies one set of command line arguments for "0_randomise_traits.R". Each run generates an output file in the directory "null_distributions". Combine these 16000 files into a single file (retaining the header only from one of the files) to generate "trait_standardised_randomised_NULL.csv". We performed this step on a computing cluster using "00000_control_randomise_traits.sh". We also repeated this exercising by setting std=FALSE in "0_randomise_traits.R" and generated "trait_randomised_NULL.csv" - although this file is not used in the downstream analyses.

## (B) Main analyses

We then perform the main analyses by knitting "1_prc_analysis.Rmd". These analyses include mainly quantitative genetic analyses (estimating additive genetic (co)variances for relative fitness at different sex ratios, estimating additive genetic variances for traits, estimating sex- and sex ratio-specific Robertson Covariances for traits, measuring genetic correlations between male reproduction related traits, and fitting a linear mixed model for female fecundity). 

Set diagnostics = TRUE in the first code chunk if the diagnostics of MCMCglmm models need to be printed out in the html output.	

These analyses require the main data file ("Comprehensive_traits.csv"), but also the "null_distributions/fitness_randomised_NULL.csv" and "null_distributions/trait_standardised_randomised_NULL.csv".

This script generates output files (figures and .csv files; see details below) in the directory "Outputs" and also generates "1_prc_analysis.html" in the root directory.

## (C) Power analysis

Finally, using simulated data, we generate estimates of statistical power to detect Robertson Covariances for various traits given our actual sample sizes and the actual additive genetic (co)variances estimated in the previous step. 

(i) First we run "2_create_parameter_grid_simulations.R" to generate "000_parameter_grid_simulations.txt", which contains command line arguments required for running "3_Simulations.R". "2_create_parameter_grid_simulations.R" picks up the actual estimates of additive genetic variances for fitness (calculated by "1_prc_analysis.Rmd") from "Output/fitness_vA_output.csv". 

(ii) Next we perform analyses on simulated data by running "3_Simulations.R" 20000 times using command line arguments provided by a given row in "2_create_parameter_grid_simulations.R" for each run. Each run generates an output in the directory "null_distributions". We combine these files into a single file (retaining the header only from one of the files) to generate "PA_output.csv". 

(iii) We then knit "4_power_analysis.rmd" to generate estimates of power for each trait which are stored within "Outputs/actual_power.csv" and depicted in figures in the "Output" directory. An html output file ("4_power_analysis.html") is also generated in the root directory of the repository. This script requires "Comprehensive_traits.csv", "null_distributions/PA_output.csv", "Output/trait_vA_output.csv", "Output/PRC_output.csv", "Output/PRC_output_sep_sr.csv", and "Output/fitness_vA_output.csv".



####################################
# List of files and subdirectories #
####################################

## Files in the root directory of the repository

### Main data

"Comprehensive_traits.csv": Data used in this study


### Scripts to generate text files containing command line arguments

"0_create_parameter_grid.R": Generates "000_parameter_grid.txt"
"2_create_parameter_grid_simulations.R": Generates "00000_control_simulations.txt"


### Text files storing command line arguments

"000_parameter_grid.txt": A text file that supplies command line arguments to "0_randomise_traits.R" (one row at a time)
"000_parameter_grid_simulations.txt": A text file that supplies command line arguments to "3_Simulations.R" (one row at a time)


### Scripts to generate null distributions to be stored in the directory "null_distributions"

"0_randomise_fitness.R": An Rscript that generates null distributions for additive genetic variance for sex and sex ratio specific fitness 
"0_randomise_traits.R": An Rscript that generates null distributions for each trait 
"3_Simulations": Generates simulated datasets and fits MCMCglmm models for power analysis

These three scripts were run on a computing cluster using the bash scripts "00000_control_randomise_fitness.sh", "00000_control_randomise_traits.sh", and "00000_control_simulations.sh", respectively.
Each script generates as many output files as there are independent runs on the cluster. Each of these are then combined into one output file for each script.


### Main analysis script

"1_prc_analysis.Rmd": An Rmarkdown file containing the R code used for performing all the principal data analysis. 
"1_prc_analysis.html": Corresponding html file


### Power analysis script

"4_power_analysis.Rmd" 
"4_power_analysis.html": corresponding html file


### null_distributions (within the subdirectory "null_distributions")

"fitness_randomised_NULL.csv": Null distribution for sex and sex ratio specific additive genetic (co)variance for relative fitness (generated using "0_randomise_fitness.R")
"trait_standardised_randomised_NULL.csv": Null distribution for additive genetic variance for each trait on the standardised scale (generated using "0_randomise_traits.R")
"trait_randomised_NULL.csv": Null distribution for additive genetic variance for each trait on the raw measurement scale (generated using "0_randomise_fitness.R") (not used in analyses presented in the paper)
"PA_output.csv": Output of fitting linear mixed models to simulated datasets to measure Robertson Covariances (generated using "3_Simulations")

### Within the "Output" directory 

This directory stores outputs generated by "1_prc_analysis.Rmd" and "4_power_analysis.Rmd" 

"fitness_vA_output.csv": Estimates of additive genetic (co)variances, residual variances, variance associated with Day:hemigenome_line for relative fitness

"trait_vA_output.csv": Estimates of additive genetic variances, residual variances, variance associated with Day:hemigenome_line for various traits

"PRC_output.csv": Estimates of Robertson Covariances for non-sex ratio traits (i.e. traits measured in a sex ratio agnostic environments)

"PRC_output_sep_sr.csv": Estimates of Robertson Covariances for sex ratio traits (i.e. traits measured at either male biased or female biased sex ratios)

"trade_off_output.csv": Additive genetic correlations between various male reproduction related traits

"actual_power.csv": Estimates of statistical power to detect sex ratio specific Robertson Covariances for various traits

Additionally, this directory also contains 20 .jpg files.


############################################################################################################################################################

########################
# Details of the files #
########################


##############################
## Comprehensive_traits.csv ##
##############################

Number of variables: 4

Number of cases/rows: 11751

Variable List: 

### Trait

This variable has 22 levels which correspond to the names of the various traits measured as follows: 

Trait level			-	Trait name (units)

CD_female			-	Copulation duration in females (minutes)
CD_male				-	Copulation duration in males (minutes)
Female_fecundity_Female_biased	-	Female fecundity at female biased sex ratio (number of eggs laid per female)
Female_fecundity_Male_biased	-	Female fecundity at male biased sex ratio (number of eggs laid per female)
Mate_fecundity_Female_biased	-	Male effect on female fecundity at female biased sex ratio (number of eggs laid per female)
Mate_fecundity_Male_biased	-	Male effect on female fecundity at male biased sex ratio (number of eggs laid per female)
ML_female			-	Mating latency in females (minutes)
ML_male				-	Mating latency in males (minutes)
MR_Female_Female_biased		-	Female mating rate at female biased sex ratio (total number of matings recorded in the observation window)
MR_Female_Male_biased		-	Female mating rate at male biased sex ratio (total number of matings recorded in the observation window)
MR_Male_Female_biased		-	Male mating rate at female biased sex ratio (total number of matings recorded in the observation window)
MR_Male_Male_biased		-	Male mating rate at male biased sex ratio (total number of matings recorded in the observation window)
P1				-	Sperm defence ability (P1)
P2				-	Sperm offence ability (P2)
RML_female			-	Female remating latency (minutes)
RML_male			-	Male mating latency with mated females (minutes)
Fitness_Female_Female_biased	-	Female fitness at female biased sex ratio (number of eggs laid per female)
Fitness_Female_Equal		-	Female fitness at equal sex ratio (number of eggs laid per female)
Fitness_Female_Male_biased	-	Female fitness at male biased sex ratio (number of eggs laid per female)
Fitness_Male_Female_biased	-	Male fitness at female biased sex ratio (proportion of progeny sired by focal males)
Fitness_Male_Equal		-	Male fitness at equal sex raito (proportion of progeny sired by focal males)
Fitness_Male_Male_biased	-	Male fitness at male biased sex ratio (proportion of progeny sired by focal males)


### Family 

Identity of the hemigenome line; "1" through "43"


### Replicate 

Each trait was measured in multiple replicate assays performed on separate days


### Measurement 

Each trait had a different unit of measurement (see above)

########################################
## 00000_control_randomise_fitness.sh ##
########################################

This is a bash script to submit a batch job to the AC3 computing cluster at Ashworth Laboratories, the University of Edinburgh.
This batch job runs the Rscript "0_randomise_fitness.R" using just a single command line argument supplied by the task ID on the cluster.

#######################################
## 00000_control_randomise_traits.sh ##
#######################################

This is a bash script to submit a batch job to the AC3 computing cluster at Ashworth Laboratories, the University of Edinburgh.
This batch job runs the Rscript "0_randomise_traits.R" using just a single command line argument supplied by rows within "000_parameter_grid.txt".

##################################
## 00000_control_simulations.sh ##
##################################

This is a bash script to submit a batch job to the AC3 computing cluster at Ashworth Laboratories, the University of Edinburgh.
This batch job runs the Rscript "3_Simulations.R" using just a single command line argument supplied by rows within "000_parameter_grid_simulations.txt".

############################
## 000_parameter_grid.txt ##
############################

A text file that supplies command line arguments to "0_randomise_traits.R"

Created using "0_create_parameter_grid.R"

number of columns = 2
number of rows = 16000 (1000 each for 16 different traits)

Column list:

### column 1 - Name of the traits

Levels:

CD_female			-	Copulation duration in females (minutes)
CD_male				-	Copulation duration in males (minutes)
Female_fecundity_Female_biased	-	Female fecundity at female biased sex ratio (number of eggs laid per female)
Female_fecundity_Male_biased	-	Female fecundity at male biased sex ratio (number of eggs laid per female)
Mate_fecundity_Female_biased	-	Male effect on female fecundity at female biased sex ratio (number of eggs laid per female)
Mate_fecundity_Male_biased	-	Male effect on female fecundity at male biased sex ratio (number of eggs laid per female)
ML_female			-	Mating latency in females (minutes)
ML_male				-	Mating latency in males (minutes)
MR_Female_Female_biased		-	Female mating rate at female biased sex ratio (total number of matings recorded in the observation window)
MR_Female_Male_biased		-	Female mating rate at male biased sex ratio (total number of matings recorded in the observation window)
MR_Male_Female_biased		-	Male mating rate at female biased sex ratio (total number of matings recorded in the observation window)
MR_Male_Male_biased		-	Male mating rate at male biased sex ratio (total number of matings recorded in the observation window)
P1				-	Sperm defence ability (P1)
P2				-	Sperm offence ability (P2)
RML_female			-	Female remating latency (minutes)
RML_male			-	Male mating latency with mated females (minutes)

### column 2 - replicate for each trait (1 to 10000)


########################################
## 000_parameter_grid_simulations.txt ##
########################################

A text file that supplies command line arguments to "3_Simulations.R"

number of columns = 5
number of rows = 20000

Column list:

### column 1 - Number of replicate neasurements for the trait of interest per hemigenome line
### column 2 - Additive genetic variance for relative fitness
### column 3 - Environmental variance for relative fitness
### column 4 - Additive genetic variance for the trait on the stadardised scale
### column 5 - Additive genetic covariance between the standardised trait and relative fitness 

###############################
## 0_create_parameter_grid.R ##
###############################

An Rscript that generates "000_parameter_grid.txt"
This must be run on a Linux system so that "000_parameter_grid.txt" can be later used on the cluster.

###########################
## 0_randomise_fitness.R ##
###########################

This script takes just one command line argument: replicate (which is included in the filename of the output)

This script performs the following steps:

- Read "Comprehensive_traits.csv"
- Select data for fitness
- Randomly permute the "Family" column
- Fit a linear mixed model implemented in MCMCglmm and estimate sex and sex ratio specific additive (as well as day:family related and residual) genetic (co)variances for relative fitness 
- Store output

To generate null distributions for additive genetic (co)variances for relative fitness, this script is run 1000 times on a computing cluster with the help of "00000_control_randomise_fitness.sh"

##########################
## 0_randomise_traits.R ##
##########################

This script takes two command line argument: 

trait - the name of the trait for which a null distribution is to be generated (possible values are described above in the description of "000_parameter_grid.txt")
replicate (which is included in the filename of the output in addition to the name of the trait)

This script has a parameter called "std". If TRUE, the trait is standardied to have a mean 0 and variance 1.

This script performs the following steps:

- Read "Comprehensive_traits.csv"
- Select data for the appropriate trait
- Randomly permute the "Family" column
- Fit a linear mixed model implemented in MCMCglmm and estimate  additive (as well as day:family related and residual) genetic variances for relative fitness 
- Store output

To generate null distribution for additive genetic variance for each trait, this script is run 1000 times for each trait on a computing cluster with the help of "00000_control_randomise_traits.sh" and "000_parameter_grid.txt"


########################
## 1_prc_analysis.Rmd ##
########################

The working directory needs to be specified at the top. 

This code performs four different analyses.

 1. Fit linear mixed effects models using the R package "MCMCglmm" on just the data for male and female fitness at female biased, equal, and male biased sex ratios to compute for each sex ratio the following quantities:

 (i) additive genetic variance for female relative fitness
 (ii) additive genetic variance for male relative fitness
 (iii) intersexual additive genetic covariance for relative fitness 

These point estimates are then plotted against the 95% credible intervals generated by 0_randomise_fitness.R (stored in "null_distributions/fitness_randomised_NULL.csv")

Outputs (including plots) are stored within the "Output" directory: "Figure_1.jpg", "Figure_S1.jpg", and fitness_vA_output.csv 

#%%%%%%#

2. Fit linear models using the R package "MCMCglmm" to estimate the additive genetic variance and 95% credible intervals for each trait. 
These point estimates are then plotted against the 95% credible intervals generated by 0_randomise_traits.R (stored in "null_distributions/trait_standardised_randomised_NULL.csv")

Outputs (including plots) are stored within the "Output" directory: "Figure_S2.jpg", and "trait_vA_output.csv" 

#%%%%%%#

3. Fit linear models using the R package "MCMCglmm" to estimate sex and sex ratio specific Price-Robertson Covariances as well as estiates of heritability for each trait (other than the six fitness traits). 

These outputs are stored within two .csv files: 

 (i) "PRC_output.csv" (for traits measured in an environment where theere was one male and one female in a vial) 
 (ii) "PRC_output_sep_sr.csv" (for traits measured at male biased or female biased sex ratios)

Following figures are stored in the "Output" directory: "Figure_2.jpg", "Figure_3.jpg", "Figure_4.jpg", "Figure_5.jpg" 

#%%%%%%#

4. Fit a linear mixed effects model using the R package "MCMCglmm" to estimate the additive genetic correlations between the following male traits:

 (i) Sperm defence ability (P1)
 (ii) Sperm offence ability (P2)
 (iii) Mating latency in males
 (iv) Male mating latency with mated females
 (v) Male effect on female fecundity at male biased sex ratio
 (vi) Male effect on female fecundity at female biased sex ratio

The following output file is stored within the "Output" directory: "trade_off_output.csv"

#%%%%%%#

4. Using a linear mixed model implemented using the R package "lme4" to investigate the effect of sex ratio on female fecundity (output stored in "prc_analysis.html")


###########################################
## 2_create_parameter_grid_simulations.R ##
###########################################

An Rscript that generates "000_parameter_grid_simulations.txt"
This must be run on a Linux system so that "000_parameter_grid_simulations.txt" can be later used on the cluster.

This script uses actual estimates of additive genetic variance for relative fitness stored within "Output/fitness_vA_output.csv" which is generated by 1_prc_analysis.Rmd


#####################
## 3_Simulations.R ##
#####################

This script takes 5 command line arguments (stored as columns of "000_parameter_grid_simulations.txt")

Column list:

### column 1 - Number of replicate neasurements for the trait of interest per hemigenome line
### column 2 - Additive genetic variance for relative fitness
### column 3 - Environmental variance for relative fitness
### column 4 - Additive genetic variance for the trait on the stadardised scale
### column 5 - Additive genetic covariance between the standardised trait and relative fitness 

Using these command line arguments, the script generates a simulated dataset and fits a linear mixed model in MCMCglmm to estimate the Robertson Covariance (RC) between the trait of interest and relative fitness.
The script then examins whether the estimated RC is significantly different from 0 and stores output.

For power analysis, this script is run on the cluster 20000 times with the help of "00000_control_simulations.sh" using command line arguments stored within "000_parameter_grid_simulations.txt".
The outout of all the 20000 runs is then combined. It is stored as "null_distributions/PA_output.csv"


##########################
## 4_power_analysis.Rmd ##
##########################

Performs power analysis using "null_distributions/PA_output.csv".

- fits a logistic regression to examine how statistical power is affected by various parameters (output stored within "4_power_analysis.html")
- plots fitted data ("Output/Figure_P1.jpg")
- Using "Output/trait_vA_output.csv", "Output/fitness_vA_output.csv", and "Comprehensive_traits.csv" predicts power to detect sex and sex ratio specific Robertson Covariances for each trait ("Output/Figure_P2.jpg", "Output/Figure_P3.jpg", "Output/Figure_P4.jpg", ..., "Output/Figure_P13.jpg")

############################################################################################################################################################

#####################################
# Files within "null_distributions" #
#####################################

#################################
## fitness_randomised_NULL.csv ##
#################################

Estimates of variance components of sex and sex ratio specific relative fitness after randomising the hemogenome line identity of data points.

Number of variables: 17

Number of cases/rows: 1000

Variable List: 

### va_fem_f_ran - additive genetic variance for female relative fitness at female biased sex ratio

### va_fem_e_ran - additive genetic variance for female relative fitness at equal sex ratio

### va_fem_m_ran - additive genetic variance for female relative fitness at male biased sex ratio

### va_male_f_ran - additive genetic variance for male relative fitness at female biased sex ratio

### va_male_e_ran - additive genetic variance for male relative fitness at equal sex ratio

### va_male_m_ran - additive genetic variance for male relative fitness at male biased sex ratio

### cov_mf_f_ran - intersexual additive genetic covariance for relative fitness at female biased sex ratio

### cov_mf_e_ran - intersexual additive genetic covariance for relative fitness at equal sex ratio

### cov_mf_m_ran - intersexual additive genetic covariance for relative fitness at male biased sex ratio

### vr_fem_f_ran - residual variance for female relative fitness at female biased sex ratio

### vr_fem_e_ran - residual variance for female relative fitness at equal sex ratio

### vr_fem_m_ran - residual variance for female relative fitness at male biased sex ratio

### vr_male_f_ran - residual variance for male relative fitness at female biased sex ratio

### vr_male_e_ran - residual variance for male relative fitness at equal sex ratio

### vr_male_m_ran - residual variance for male relative fitness at male biased sex ratio

### day_family_ran - variance associated with day:hemigenome_line

### unique_stamp - Unique time stamp of the analysis including the node (on the AC3 computing cluster at UoE) where the analysis was run


################################
## traits_randomised_NULL.csv ##
################################

Estimates of variance components of various traits (on the measurement (non-standardised) scale) after randomising the hemogenome line identity of data points.

Number of variables: 6

Number of cases/rows: 16000

Variable List: 

### va_trait - additive genetic variance for the (non-standardised) trait

### vr_trait - residual variance for the (non-standardised) trait

### h2_trait - heritability for the (non-standardised) trait

### day_family_ran - variance associated with day:hemigenome_line

### Trait 

This variable has 16 levels which correspond to the names of the various traits measured as follows: 

Trait level			-	Trait name (units)

CD_female			-	Copulation duration in females (minutes)
CD_male				-	Copulation duration in males (minutes)
Female_fecundity_Female_biased	-	Female fecundity at female biased sex ratio (number of eggs laid per female)
Female_fecundity_Male_biased	-	Female fecundity at male biased sex ratio (number of eggs laid per female)
Mate_fecundity_Female_biased	-	Male effect on female fecundity at female biased sex ratio (number of eggs laid per female)
Mate_fecundity_Male_biased	-	Male effect on female fecundity at male biased sex ratio (number of eggs laid per female)
ML_female			-	Mating latency in females (minutes)
ML_male				-	Mating latency in males (minutes)
MR_Female_Female_biased		-	Female mating rate at female biased sex ratio (total number of matings recorded in the observation window)
MR_Female_Male_biased		-	Female mating rate at male biased sex ratio (total number of matings recorded in the observation window)
MR_Male_Female_biased		-	Male mating rate at female biased sex ratio (total number of matings recorded in the observation window)
MR_Male_Male_biased		-	Male mating rate at male biased sex ratio (total number of matings recorded in the observation window)
P1				-	Sperm defence ability (P1)
P2				-	Sperm offence ability (P2)
RML_female			-	Female remating latency (minutes)
RML_male			-	Male mating latency with mated females (minutes)


### unique_stamp - Unique time stamp of the analysis including the node (on the AC3 computing cluster at UoE) where the analysis was run


#############################################
## traits_standardised_randomised_NULL.csv ##
#############################################

Estimates of variance components of various traits (on the standardised scale) after randomising the hemogenome line identity of data points.

Number of variables: 6

Number of cases/rows: 16000

Variable List: 

### va_trait - additive genetic variance for the (standardised) trait

### vr_trait - residual variance for the (standardised) trait

### h2_trait - heritability for the (standardised) trait

### day_family_ran - variance associated with day:hemigenome_line

### Trait 

This variable has 16 levels which correspond to the names of the various traits measured as follows: 

Trait level			-	Trait name (units)

CD_female			-	Copulation duration in females (minutes)
CD_male				-	Copulation duration in males (minutes)
Female_fecundity_Female_biased	-	Female fecundity at female biased sex ratio (number of eggs laid per female)
Female_fecundity_Male_biased	-	Female fecundity at male biased sex ratio (number of eggs laid per female)
Mate_fecundity_Female_biased	-	Male effect on female fecundity at female biased sex ratio (number of eggs laid per female)
Mate_fecundity_Male_biased	-	Male effect on female fecundity at male biased sex ratio (number of eggs laid per female)
ML_female			-	Mating latency in females (minutes)
ML_male				-	Mating latency in males (minutes)
MR_Female_Female_biased		-	Female mating rate at female biased sex ratio (total number of matings recorded in the observation window)
MR_Female_Male_biased		-	Female mating rate at male biased sex ratio (total number of matings recorded in the observation window)
MR_Male_Female_biased		-	Male mating rate at female biased sex ratio (total number of matings recorded in the observation window)
MR_Male_Male_biased		-	Male mating rate at male biased sex ratio (total number of matings recorded in the observation window)
P1				-	Sperm defence ability (P1)
P2				-	Sperm offence ability (P2)
RML_female			-	Female remating latency (minutes)
RML_male			-	Male mating latency with mated females (minutes)


### unique_stamp - unique time stamp of the analysis including the node (on the AC3 computing cluster at UoE) where the analysis was run


###################
## PA_output.csv ##
###################

Outputs of fitting linear mixed models using MCMCglmm to simulated data (for power analysis).

Number of variables: 14

Number of cases/rows: 20000

Variable List: 

### nlines - number of hemigenome lines

### nrep_t - number of replicate measurements for each line for the focal trait

### nrep_w - number of replicate measurements for each line for fitness

### vA_t - the true additive genetic variance for the trait on the standardised scale

### vA_w - the true additive genetic variance for relative fitness

### vE_w - the true environmental variance for relative fitness

### COV_tw - the true additive genetic covariance between the (standardised trait) and relative fitness, i.e. the true Robertson Covariance

### vA_t_est - the estimate of vA_t from the MCMCglmm model

### vA_w_est - the estimate of vA_w from the MCMCglmm model

### COV_tw_est - the estimate of COV_tw from the MCMCglmm model

### COV_tw_est_lower - the lower 95% credible interval for COV_tw from the MCMCglmm model

### COV_tw_est_upper - the upper 95% credible interval for COV_tw from the MCMCglmm model

### significance - 0 if the 95% credible intervals of COV_tw overlap with 0, otherwise 1

### unique_stamp - unique time stamp of the analysis including the node (on the AC3 computing cluster at UoE) where the analysis was run


############################################################################################################################################################

#########################
# Files within "Output" #
#########################

###########################
## fitness_vA_output.csv ##
###########################

The output of fitting linear mixed model to sex and sex ratio specific relative fitness data using MCMCglmm.

Number of variables: 12

Number of cases/rows: 9

Variable List: 

### Sex

This variable has three levels

Female Vw : Relates to female relative fitness
Male Vw : Relates to male relative fitness
COVmf,w : Relates to intersexual covariance for relative fitness

### Sex.Ratio

This variable has three levels: "Female Biased", "Equal", and "Male Biased"

### Va : estimate of additive genetic (co)variance for relative fitness (additive genetic variance when Sex == "Female Vw" or "Male Vw"; intersexual additive genetic covariance when Sex == "COVmf,w")

### Va_L : lower 95% credible interval for Va

### Va_U : upper 95% credible interval for Va

### Vr : estimate of residual variance for relative fitness

### Vr_L : lower 95% credible interval for Vr

### Vr_U : upper 95% credible interval for Vr

### Va_null_L : lower 95% credible interval of the null distribution of the corresponding additive genetic (co)variance

### Va_null_U : upper 95% credible interval of the null distribution of the corresponding additive genetic (co)variance

### Va_for_table1 : combining Va, Va_L, Va_U for copying into a manuscript table

### Vr_for_table1 : combining Vr, Vr_L, Vr_U for copying into a manuscript table 


#########################
## trait_vA_output.csv ##
#########################

The output of fitting linear mixed model to standardised trait data using MCMCglmm separately for each trait.

Number of variables: 25

Number of cases/rows: 16

Variable List: 

### trait

This variable has 16 levels which correspond to the names of the various traits measured as follows: 

Trait level			-	Trait name (units)

CD_female			-	Copulation duration in females (minutes)
CD_male				-	Copulation duration in males (minutes)
Female_fecundity_Female_biased	-	Female fecundity at female biased sex ratio (number of eggs laid per female)
Female_fecundity_Male_biased	-	Female fecundity at male biased sex ratio (number of eggs laid per female)
Mate_fecundity_Female_biased	-	Male effect on female fecundity at female biased sex ratio (number of eggs laid per female)
Mate_fecundity_Male_biased	-	Male effect on female fecundity at male biased sex ratio (number of eggs laid per female)
ML_female			-	Mating latency in females (minutes)
ML_male				-	Mating latency in males (minutes)
MR_Female_Female_biased		-	Female mating rate at female biased sex ratio (total number of matings recorded in the observation window)
MR_Female_Male_biased		-	Female mating rate at male biased sex ratio (total number of matings recorded in the observation window)
MR_Male_Female_biased		-	Male mating rate at female biased sex ratio (total number of matings recorded in the observation window)
MR_Male_Male_biased		-	Male mating rate at male biased sex ratio (total number of matings recorded in the observation window)
P1				-	Sperm defence ability (P1)
P2				-	Sperm offence ability (P2)
RML_female			-	Female remating latency (minutes)
RML_male			-	Male mating latency with mated females (minutes)

### va_trait_true - estimate of additive genetic variance for standardised traits

### va_trait_true_l - lower 95% credible interval of va_trait_true
 
### va_trait_true_u - upper 95% credible interval of va_trait_true

### vr_trait_true - estimate of residual variance for standardised traits

### vr_trait_true_l - lower 95% credible interval for vr_trait_true

### vr_trait_true_u - upper 95% credible interval for vr_trait_true

### h2_trait_true - estimate of heritability

### h2_trait_true_l - lower 95% credible interval for h2_trait_true

### h2_trait_true_u - upper 95% credible interval for h2_trait_true

### day_family_true - variance associated with day:hemigenome_line

### day_family_true_l - lower 95% credible interval for day_family_true

### day_family_true_u - upper 95% credible interval for day_family_true

### va_trait_null_l - lower 95% credible interval of the null distribution of the additive genetic variance for standardised traits

### va_trait_null_u - upper 95% credible interval of the null distribution of the additive genetic variance for standardised traits

### vr_trait_null_l - lower 95% credible interval of the null distribution of the residual variance for standardised traits

### vr_trait_null_u - upper 95% credible interval of the null distribution of the residual variance for standardised traits

### h2_trait_null_l - lower 95% credible interval of the null distribution of the trait heritability

### h2_trait_null_u - upper 95% credible interval of the null distribution of the trait heritability

### day_family_null_l - lower 95% credible interval of the null distribution of the variance associated with day:hemigenome_line

### day_family_null_u - upper 95% credible interval of the null distribution of the variance associated with day:hemigenome_line

### trait_names_for_table - names of various traits as they should appear in the figures

### va_for_table - estimate and the CIs of va_trait combined for copying into a manuscript table

### vr_for_table - estimate and the CIs of vr_trait combined for copying into a manuscript table

### day_family_for_table - estimate and the CIs of day_family combined for copying into a manuscript table


###########################
## PRC_output_sep_sr.csv ##
###########################

Sex and sex ratio specific Robertson Covariances for traits measured at either male biased or female biased sex ratios (i.e. sex ratio traits)

Number of variables: 13

Number of cases/rows: 4

Variable List: 

### trait

This variable has 4 levels which correspond to the names of the various traits measured as follows:

Female_fecundity - Fecundity of females post exposure to males for two days at specific sex ratios	
Mate_fecundity - Male effect on female fecundity (number of eggs laid per female)
MR_Female - Female mating rate
MR_Male - Male mating rate


### cov_trait_femaleW_fb - Additive genetic covariance [95% credible intervals inside parentheses] with female relative fitness at female biased sex ratio

### cov_trait_femaleW_mb - Additive genetic covariance [95% credible intervals inside parentheses] with female relative fitness at male biased sex ratio

### diff_trait_femaleW - Difference between cov_trait_femaleW_mb and cov_trait_femaleW_fb [95% credible intervals inside parentheses]

### cov_trait_maleW_fb - Additive genetic covariance [95% credible intervals inside parentheses] with male relative fitness at female biased sex ratio

### cov_trait_maleW_mb - Additive genetic covariance [95% credible intervals inside parentheses] with male relative fitness at male biased sex ratio

### diff_trait_maleW - Difference between cov_trait_maleW_mb and cov_trait_maleW_fb [95% credible intervals inside parentheses]

### h2_trait_f_fb - heritability of the trait at female biased sex ratio obtained from the model including female fitness data [95% credible intervals inside parentheses]

### h2_trait_f_mb - heritability of the trait at male biased sex ratio obtained from the model including female fitness data [95% credible intervals inside parentheses]

### h2_trait_m_fb - heritability of the trait at female biased sex ratio obtained from the model including male fitness data [95% credible intervals inside parentheses]

### h2_trait_m_mb - heritability of the trait at male biased sex ratio obtained from the model including male fitness data [95% credible intervals inside parentheses]

### rep_f - Variance associated with replicate:hemigenome_line in the model including female fitness data [95% credible intervals inside parentheses]

### rep_m - Variance associated with replicate:hemigenome_line in the model including male fitness data [95% credible intervals inside parentheses]


####################
## PRC_output.csv ##
####################
	
Sex and sex ratio specific Robertson Covariances for traits measured in sex ratio agnostic environments (i.e. non sex ratio traits)

Number of variables: 13

Number of cases/rows: 8

Variable List: 

### trait

This variable has 8 levels which correspond to the names of the various traits measured as follows:

CD_female			-	Copulation duration in females (minutes)
CD_male				-	Copulation duration in males (minutes)
ML_female			-	Mating latency in females (minutes)
ML_male				-	Mating latency in males (minutes)
P1				-	Sperm defence ability (P1)
P2				-	Sperm offence ability (P2)
RML_female			-	Female remating latency (minutes)
RML_male			-	Male mating latency with mated females (minutes)


### cov_trait_femaleW_fb - Additive genetic covariance [95% credible intervals inside parentheses] with female relative fitness at female biased sex ratio

### cov_trait_femaleW_e - Additive genetic covariance [95% credible intervals inside parentheses] with female relative fitness at equal sex ratio

### cov_trait_femaleW_mb - Additive genetic covariance [95% credible intervals inside parentheses] with female relative fitness at male biased sex ratio

### diff_trait_femaleW - Difference between cov_trait_femaleW_mb and cov_trait_femaleW_fb [95% credible intervals inside parentheses]

### cov_trait_maleW_fb - Additive genetic covariance [95% credible intervals inside parentheses] with male relative fitness at female biased sex ratio

### cov_trait_maleW_e - Additive genetic covariance [95% credible intervals inside parentheses] with male relative fitness at equal sex ratio

### cov_trait_maleW_mb - Additive genetic covariance [95% credible intervals inside parentheses] with male relative fitness at male biased sex ratio

### diff_trait_maleW - Difference between cov_trait_maleW_mb and cov_trait_maleW_fb [95% credible intervals inside parentheses]

### h2_trait_f - heritability of the trait obtained from the model including female fitness data [95% credible intervals inside parentheses]

### h2_trait_m - heritability of the trait obtained from the model including male fitness data [95% credible intervals inside parentheses]

### rep_f - Variance associated with replicate:hemigenome_line in the model including female fitness data [95% credible intervals inside parentheses]

### rep_m - Variance associated with replicate:hemigenome_line in the model including male fitness data [95% credible intervals inside parentheses]

##########################
## trade_off_output.csv ##
##########################

Every data cell in the table represents the additive genetic correlation between a pair of male reproduction related traits whose identities can be obtained from the first column in the corresponding row, and the second row in the corresponding column.

######################
## actual_power.csv ##
######################

Estimates of the statistical power (expressed as %) to detect additive genetic covariance of a given trait with sex and sex ratio specific relative fitness 

Number of variables: 6

Number of cases/rows: 12

Variable List: 

### trait

This variable has 12 levels:

CD_female
CD_male
Female_fecundity
Mate_fecundity
ML_female
ML_male
MR_Female
MR_Male
P1
P2
RML_female
RML_male



### power_femaleW_fb - power to detect additive genetic covariance with female relative fitness at female biased sex ratio

### power_femaleW_mb - power to detect additive genetic covariance with female relative fitness at male biased sex ratio

### power_maleW_fb - power to detect additive genetic covariance with male relative fitness at female biased sex ratio

### power_maleW_mb - power to detect additive genetic covariance with male relative fitness at male biased sex ratio

### trait_names

This variable has 12 levels:

Copulation duration in females
Copulation duration in males
Female fecundity
Male effect on female fecundity
Female latency to first mating
Male latency to first mating
Female mating rate
Male mating rate
Sperm defence ability (P1)
Sperm offence ability (P2)
Female remating latency
Male mating latency with mated females



